package com.thinktank.controller;

import static com.thinktank.util.DbUtil.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.thinktank.dao.*;
import com.thinktank.vo.*;

public class GuestRegProcessController implements Controller {
	public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 정보 받아와서 객체 세팅
		request.setCharacterEncoding("utf-8");
		String gWriter = request.getParameter("gWriter");
		HttpSession session = request.getSession();
		Member master = (Member)session.getAttribute("master");
		String gContent = request.getParameter("gContent");

		System.out.println("등로옥:::::::::::::::::::::::::::::::::"+master);
		// gContent 엔터 허용
		gContent = gContent.replaceAll("\r\n", "<br />");
		
		GuestVo guestVo = new GuestVo();
		guestVo.setgMaster(master.getmNo()+"");
		guestVo.setgWriter(gWriter);
		guestVo.setgContent(gContent);

		System.out.println("----------------" + master.getmNo());
		
		// DB 작업
		Connection con = getConnection();
		GuestDao dao = new GuestDao(con);
		int result = dao.insert(guestVo);
		close(con);
		if(result == 0) {
			return "error.jsp";
		}
		
		return "redirect:guest_write.jsp";
	}
}
